/**
 *  rtc.c - The RTC driver.
 *
 *  Copyright (C) 2008-2010 ZhangHu
 *  All rights reserved.
 *  E-MAIL: anmnmnly@gmail.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
#include "drivers/rtc.h"
#include "devs.h"


extern void init_rtc(void);
extern void write_rtc(const rtc_t *value);
extern void read_rtc(rtc_t *value);



static int32 rtc_ioctl(uint32 cmd, void *arg)
{
    rtc_t *prtc = NULL;
    const rtc_t *pconst_rtc = NULL;

    if((cmd != (uint32)RTC_CMD_WRITE) && (cmd != (uint32)RTC_CMD_READ)) {
        return(-1);
    }

    if(cmd == (uint32)RTC_CMD_WRITE) {
        pconst_rtc = (const rtc_t*)(arg);
        write_rtc(pconst_rtc);
    } else {
        prtc = (rtc_t*)(arg);
        read_rtc(prtc);
    }

    return(0);
}



struct chdev_operations rtc_op = {
    NULL,
    NULL,
    NULL,
    NULL,
    rtc_ioctl,
    NULL
};



void rtc_register(void)
{
    init_rtc();

    chdevRegister(RTC_ID, RTC0_ID, RTC, 0, &rtc_op);
}


